/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 15, 2011 9:14:50 PM
 */
package carrello.model.association;

import carrello.model.entitydao.*;
import carrello.model.entities.*;
import java.util.Set;
import static carrello.util.EntityManagerUtil.getEntityManager;

public class CategoryHasAttributes implements AbstractAssociation{
    private Set<Category> categories;
    private Set<Attribute> attributes;
    private Category category;
    
    public CategoryHasAttributes(Set<Category> category, Set<Attribute> attribute)
    {
        this.attributes = attribute;
        this.categories = category;
    }
    
    public CategoryHasAttributes(Category category, Set<Attribute> attributes)
    {
        this.category = category;
        this.attributes = attributes;
    }
    public void save() 
    {
        this.category.setAttribute(attributes);
        new CategoryDAO().create(category);
        new AttributeDAO().createAll(attributes);
    }
    
    public void deleteAll() {
        getEntityManager().removeAll(attributes);
    }

    public void saveAll() {
        for (Category category : categories) {
            category.setAttribute(attributes);
            new CategoryDAO().create(category);
        } // for
        new AttributeDAO().createAll(attributes);
    }

    public void delete() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void update() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
